﻿using Core.Entities.EC;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Data.Configurations.EC
{
    /// <summary>
    /// 能源信息管理配置
    /// </summary>
    public class EnergyConfiguration : IEntityTypeConfiguration<Energy>
    {
        public void Configure(EntityTypeBuilder<Energy> builder)
        {
            // 设置表名
            builder.ToTable("EC_Energy");

            // 配置主键
            builder.HasKey(e => e.Id);

            // 属性配置
            builder.Property(e => e.Id)
                .HasColumnName("ID")
                .HasMaxLength(50);

            builder.Property(e => e.DevName)
                .HasColumnName("DevName")
                .HasMaxLength(255);

            builder.Property(e => e.FactoryName)
                .HasColumnName("FactoryName")
                .HasMaxLength(255);

            builder.Property(e => e.Workshop)
                .HasColumnName("Workshop")
                .HasMaxLength(255);

            builder.Property(e => e.ProductionLine)
                .HasColumnName("ProductionLine")
                .HasMaxLength(255);

            builder.Property(e => e.CreateTime)
                .HasColumnName("CreateTime");

            builder.Property(e => e.Substance)
                .HasColumnName("Substance")
                .HasMaxLength(255);

            builder.Property(e => e.EnergyConsumption)
                .HasColumnName("EnergyConsumption")
                .HasColumnType("decimal(18, 2)");

            builder.Property(e => e.Unit)
                .HasColumnName("Unit")
                .HasMaxLength(20);

            builder.Property(e => e.Remaker)
                .HasColumnName("Remaker")
                .HasMaxLength(500);

            // 索引配置
            builder.HasIndex(e => e.DevName)
                .HasDatabaseName("IX_EC_Energy_DevName");

            builder.HasIndex(e => e.FactoryName)
                .HasDatabaseName("IX_EC_Energy_FactoryName");

            builder.HasIndex(e => e.Workshop)
                .HasDatabaseName("IX_EC_Energy_Workshop");

            builder.HasIndex(e => e.Substance)
                .HasDatabaseName("IX_EC_Energy_Substance");


        }
    }
}